package com.guaoran.activity.controller;

import com.guaoran.activity.commons.ResultResp;
import com.guaoran.activity.controller.support.ResponseData;
import com.guaoran.activity.draw.ActivityTurntableDrawService;
import com.guaoran.activity.draw.bean.ActivityTurntableDrawReq;
import com.guaoran.activity.draw.bean.AwardDrawRecordBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 转盘抽奖
 */
@RestController
public class DrawController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    // 活动转盘抽奖服务
    @Autowired
    ActivityTurntableDrawService activityTurntableDrawService;


    @PostMapping("/doDraw")
    public ResponseData doDraw() {
        // 封装活动抽奖的数据：用户uid
        ActivityTurntableDrawReq drawReq = new ActivityTurntableDrawReq();
        drawReq.setUid(Integer.parseInt(getUid()));

        // 进行抽奖
        ResultResp<AwardDrawRecordBean> resp = activityTurntableDrawService.doDraw(drawReq);

        // 返回结果
        ResponseData data = new ResponseData();
        data.setCode(resp.getReturnCodeEnum().getCode());
        data.setMessage(resp.getReturnCodeEnum().getMsg());
        data.setData(resp.getResult());
        return data;
    }
}
